package com.avic.modules.statistics.service.impl;

import com.avic.common.service.impl.BaseServiceImpl;
import com.avic.modules.statistics.domain.MonthlyStatistics;
import com.avic.modules.statistics.service.MonthlyStatisticsService;
import com.avic.modules.statistics.service.mapper.MonthlyStatisticsMapper;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zhangzikang
 * @date 2022-08-14
 */
@Service(value = "monthlyStatisticsService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class MonthlyStatisticsServiceImpl extends BaseServiceImpl
        <MonthlyStatisticsMapper, MonthlyStatistics> implements MonthlyStatisticsService {

    private final MonthlyStatisticsMapper monthlyStatisticsMapper;

    public MonthlyStatisticsServiceImpl(MonthlyStatisticsMapper monthlyStatisticsMapper) {
        this.monthlyStatisticsMapper = monthlyStatisticsMapper;
    }

    @Override
    @Scheduled(cron = "0 0 1 1 * ?")
    public void del() {
        monthlyStatisticsMapper.del();
    }

    @Override
    public MonthlyStatistics queryMonthlyStatistics(String equipId) {
        return monthlyStatisticsMapper.selectEquipId(equipId);
    }

    @Override
    public void addMonthlyStatistics(MonthlyStatistics monthlyStatistics) {
        monthlyStatisticsMapper.insert(monthlyStatistics);
    }

    @Override
    public void eatMonthlyStatistics(MonthlyStatistics monthlyStatistics) {
        monthlyStatisticsMapper.updateById(monthlyStatistics);
    }
}
